package demo2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 *  一副牌
 *   买牌
 *   洗牌
 *   发牌
 */
public class Pokers {
    public static final String[] SUITS = {"♥","♠","♣","♦"};
    //买牌
    public static List<Poker> buyPokers(){
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            String suit = SUITS[i];
            for (int j = 1; j <= 13; j++) {
                Poker poker = new Poker(suit,j);
                pokerList.add(poker);
            }
        }
        return pokerList;
    }
    //交换
    public static void swap(List<Poker> pokerList,int index,int i){
        Poker tmp = pokerList.get(index);
        pokerList.set(index,pokerList.get(i));
        pokerList.set(i,tmp);
    }
    //洗牌
    public static void shuffle(List<Poker> pokerList){
        Random random = new Random();
        for (int i = pokerList.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(pokerList,index,i);
        }
    }

    public static void main(String[] args) {
       List<Poker> pokerList = buyPokers();
       System.out.println("买牌："+pokerList);
       shuffle(pokerList);
       System.out.println("洗牌"+pokerList);

       //揭牌:3个人 每个人轮流抓5张牌

        //1、如何去描述3个人？
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();

        //如何区分往哪个人手里放牌？
        List<List<Poker>> pokerTmp = new ArrayList<>();
        pokerTmp.add(hand1);
        pokerTmp.add(hand2);
        pokerTmp.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                List<Poker> hand = pokerTmp.get(j);
                hand.add(pokerList.remove(0));
            }
        }
        for (int i = 0; i < pokerTmp.size(); i++) {
            System.out.println("第"+i+"个人的牌是："+pokerTmp.get(i));
        }
        System.out.println("剩余的牌："+pokerList);
    }
}
